<?php

namespace Modules\Auth\Transformers;

use Illuminate\Http\Resources\Json\JsonResource;
use Spatie\Permission\Models\Permission;
class MyInfoTransformer extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request
     * @return array
     */
    public function toArray($request)
    {
        $func = function($v){
            return $v->name;
        };
       
        return [
            'user' => [
                'id'=> $this->id,
                'username'=>$this->name
            ],
            'permissions' => $this->super_admin ?
                Permission::all()->map($func) :
                $this->getPermissionsViaRoles()->map($func)
        ];
    }
}
